package picturewolrd;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Label;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;

public class Screen extends javax.swing.JFrame {

    //private File file;
    private File[] fileArray;
    private BufferedImage bufferedImage;
    private double rate = 1;

    public Screen() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelShowImage = new javax.swing.JPanel();
        jLabelShowImage = new javax.swing.JLabel();
        jPanelShowList = new javax.swing.JPanel();
        jPanelShowSlide = new javax.swing.JPanel();
        jPanelButton = new javax.swing.JPanel();
        jButtonTurnLeft = new javax.swing.JButton();
        jButtonZoomDown = new javax.swing.JButton();
        jButtonPrint = new javax.swing.JButton();
        jButtonMail = new javax.swing.JButton();
        jButtonLoadImage = new javax.swing.JButton();
        jButtonTurnRight = new javax.swing.JButton();
        jButtonZoomUp = new javax.swing.JButton();
        jPanelAlbum = new javax.swing.JPanel();
        jPanelCreateAlbum = new javax.swing.JPanel();
        jButtonCreateAlbum = new javax.swing.JButton();
        jPanelSearch = new javax.swing.JPanel();
        jTextFieldSearch = new javax.swing.JTextField();
        jButtonSearch = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName(""); // NOI18N
        setResizable(false);

        jPanelShowImage.setName(""); // NOI18N

        javax.swing.GroupLayout jPanelShowImageLayout = new javax.swing.GroupLayout(jPanelShowImage);
        jPanelShowImage.setLayout(jPanelShowImageLayout);
        jPanelShowImageLayout.setHorizontalGroup(
            jPanelShowImageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelShowImageLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelShowImage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelShowImageLayout.setVerticalGroup(
            jPanelShowImageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelShowImageLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelShowImage, javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanelShowListLayout = new javax.swing.GroupLayout(jPanelShowList);
        jPanelShowList.setLayout(jPanelShowListLayout);
        jPanelShowListLayout.setHorizontalGroup(
            jPanelShowListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 104, Short.MAX_VALUE)
        );
        jPanelShowListLayout.setVerticalGroup(
            jPanelShowListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanelShowSlideLayout = new javax.swing.GroupLayout(jPanelShowSlide);
        jPanelShowSlide.setLayout(jPanelShowSlideLayout);
        jPanelShowSlideLayout.setHorizontalGroup(
            jPanelShowSlideLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanelShowSlideLayout.setVerticalGroup(
            jPanelShowSlideLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jButtonTurnLeft.setText("Turn left");
        jButtonTurnLeft.setName(""); // NOI18N
        jButtonTurnLeft.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonTurnLeftActionPerformed(evt);
            }
        });

        jButtonZoomDown.setText("Zoom down");
        jButtonZoomDown.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonZoomDownActionPerformed(evt);
            }
        });

        jButtonPrint.setText("Print");

        jButtonMail.setText("Mail");

        jButtonLoadImage.setText("Load image");
        jButtonLoadImage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLoadImageActionPerformed(evt);
            }
        });

        jButtonTurnRight.setText("Turn right");
        jButtonTurnRight.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonTurnRightActionPerformed(evt);
            }
        });

        jButtonZoomUp.setText("Zoom up");
        jButtonZoomUp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonZoomUpActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelButtonLayout = new javax.swing.GroupLayout(jPanelButton);
        jPanelButton.setLayout(jPanelButtonLayout);
        jPanelButtonLayout.setHorizontalGroup(
            jPanelButtonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelButtonLayout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jButtonLoadImage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonTurnLeft, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonTurnRight, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonZoomUp, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonZoomDown, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(180, 180, 180)
                .addComponent(jButtonPrint, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonMail, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelButtonLayout.setVerticalGroup(
            jPanelButtonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelButtonLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelButtonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonTurnRight, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonLoadImage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonPrint, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonMail, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonTurnLeft, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonZoomUp, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonZoomDown, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanelAlbumLayout = new javax.swing.GroupLayout(jPanelAlbum);
        jPanelAlbum.setLayout(jPanelAlbumLayout);
        jPanelAlbumLayout.setHorizontalGroup(
            jPanelAlbumLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanelAlbumLayout.setVerticalGroup(
            jPanelAlbumLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jButtonCreateAlbum.setText("Create Album");

        javax.swing.GroupLayout jPanelCreateAlbumLayout = new javax.swing.GroupLayout(jPanelCreateAlbum);
        jPanelCreateAlbum.setLayout(jPanelCreateAlbumLayout);
        jPanelCreateAlbumLayout.setHorizontalGroup(
            jPanelCreateAlbumLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelCreateAlbumLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jButtonCreateAlbum, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(25, 25, 25))
        );
        jPanelCreateAlbumLayout.setVerticalGroup(
            jPanelCreateAlbumLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelCreateAlbumLayout.createSequentialGroup()
                .addComponent(jButtonCreateAlbum, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(7, 7, 7))
        );

        jButtonSearch.setText("Search");

        javax.swing.GroupLayout jPanelSearchLayout = new javax.swing.GroupLayout(jPanelSearch);
        jPanelSearch.setLayout(jPanelSearchLayout);
        jPanelSearchLayout.setHorizontalGroup(
            jPanelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelSearchLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldSearch)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelSearchLayout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addComponent(jButtonSearch, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(25, 25, 25)))
                .addContainerGap())
        );
        jPanelSearchLayout.setVerticalGroup(
            jPanelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelSearchLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextFieldSearch)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonSearch, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelShowList, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelShowImage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelShowSlide, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelCreateAlbum, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelAlbum, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelSearch, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanelShowImage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanelAlbum, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(11, 11, 11)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanelCreateAlbum, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanelShowSlide, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanelButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanelSearch, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(jPanelShowList, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonTurnLeftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonTurnLeftActionPerformed
        Thread threadTurnLeft = new Thread() 
        {
            @Override
            public void run() 
            {
                if(bufferedImage == null)
                    return;
                //Image image = imageIcon.getImage();
                int getWidth = bufferedImage.getWidth();
                int getHeight = bufferedImage.getHeight();
                AffineTransform affineTransform = new AffineTransform();
                affineTransform.translate(0,getHeight);
                affineTransform.rotate(Math.toRadians(270));
                AffineTransformOp affineTransformOp = new AffineTransformOp(affineTransform , AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
                //bufferedImage = affineTransformOp.filter(bufferedImage, null);
                BufferedImage bufferedThumb = new BufferedImage(getWidth , getHeight, BufferedImage.TYPE_INT_ARGB);
                bufferedImage = affineTransformOp.filter(bufferedImage, bufferedThumb);
                int tmp = getWidth;
                getWidth = getHeight;
                getHeight = tmp;
                ImageIcon imageIcon = new ImageIcon(bufferedImage);

                if(getWidth < imageIcon.getIconWidth() || getHeight < imageIcon.getIconHeight())
                {
                        getWidth = imageIcon.getIconWidth();
                        getHeight = imageIcon.getIconHeight();
                }
                
                
                Image image = imageIcon.getImage();
                Graphics graphics = bufferedImage.createGraphics();
                graphics.drawImage(image, 0, 0,getWidth ,getHeight , null, null);// ve anh theo kich thuoc da lay
                Screen.this.jLabelShowImage.setIcon(imageIcon);
            }
        };
        threadTurnLeft.start();
    }//GEN-LAST:event_jButtonTurnLeftActionPerformed

    private void jButtonTurnRightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonTurnRightActionPerformed
        Thread threadTurnRight = new Thread() 
        {
            @Override
            public void run() 
            {
                if(bufferedImage == null)
                    return;
                //Image image = imageIcon.getImage();
                int getWidth = bufferedImage.getWidth();
                int getHeight = bufferedImage.getHeight();
                AffineTransform affineTransform = new AffineTransform();
                affineTransform.translate(getHeight,0);
                affineTransform.rotate(Math.toRadians(90));
                AffineTransformOp affineTransformOp = new AffineTransformOp(affineTransform , AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
                //bufferedImage = affineTransformOp.filter(bufferedImage, null);
                BufferedImage bufferedThumb = new BufferedImage(getWidth , getHeight, BufferedImage.TYPE_INT_ARGB);
                bufferedImage = affineTransformOp.filter(bufferedImage, bufferedThumb);
                int tmp = getWidth;
                getWidth = getHeight;
                getHeight = tmp;
                ImageIcon imageIcon = new ImageIcon(bufferedImage);

                if(getWidth < imageIcon.getIconWidth() || getHeight < imageIcon.getIconHeight())
                {
                        getWidth = imageIcon.getIconWidth();
                        getHeight = imageIcon.getIconHeight();
                }
                
                
                Image image = imageIcon.getImage();
                Graphics graphics = bufferedImage.createGraphics();
                graphics.drawImage(image, 0, 0,getWidth ,getHeight , null, null);// ve anh theo kich thuoc da lay
                Screen.this.jLabelShowImage.setIcon(imageIcon);
            }
        };
        threadTurnRight.start();

    }//GEN-LAST:event_jButtonTurnRightActionPerformed

    private void jButtonZoomUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonZoomUpActionPerformed
        Thread threadZoomUp = new Thread()
        {
            @Override
            public void run()
            {
                if(bufferedImage == null) 
                    return;
                rate += 0.1;
                //rate = Math.min(10, rate);
                
                ImageIcon imageIcon = new ImageIcon(bufferedImage);
                
                int width = (int)(imageIcon.getIconWidth()*rate);
                int height = (int)(imageIcon.getIconHeight()*rate);

                if(width > bufferedImage.getWidth() || height < bufferedImage.getHeight())
                {
                        width = bufferedImage.getWidth();
                        height = bufferedImage.getHeight();
                }
                
                
                
                AffineTransform affineTransform = new AffineTransform();
                affineTransform.setToScale(rate, rate);

                AffineTransformOp affineTransformOp = new AffineTransformOp(affineTransform , AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
                BufferedImage bufferedThumb = new BufferedImage(width , height, BufferedImage.TYPE_INT_ARGB);
                
                BufferedImage bufferedImage2 = affineTransformOp.filter(bufferedImage,bufferedThumb);
                imageIcon = new ImageIcon(bufferedImage2);
                
                //imageIcon = new ImageIcon(bufferedImage);
                
                Image image = imageIcon.getImage();
                Graphics graphics = bufferedImage2.createGraphics();
                graphics.drawImage(image, 0, 0,width ,height , null, null);// ve anh theo kich thuoc da lay
                
                Screen.this.jLabelShowImage.setIcon(imageIcon);
             }
        };
        threadZoomUp.start();       
    }//GEN-LAST:event_jButtonZoomUpActionPerformed

    private void jButtonLoadImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLoadImageActionPerformed
        Thread threadLoadImage = new Thread() {
            @Override
            public void run() {
                JFileChooser jFileChooser = new JFileChooser();
                int imageChoose = jFileChooser.showOpenDialog(new Label()); // show dialog chon file
                if (imageChoose == JFileChooser.APPROVE_OPTION)// chon file ko loi thi if
                {
                    File file = jFileChooser.getSelectedFile(); // lay file chon
                    ImageIcon imageIcon = new ImageIcon(file.getPath());//
                    Image image = imageIcon.getImage(); // lay anh 
                    bufferedImage = new BufferedImage(jLabelShowImage.getWidth(), jLabelShowImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
                    
                    int getWidth = imageIcon.getIconWidth(); 
                    int getHeight = imageIcon.getIconHeight();
                    if(getWidth > bufferedImage.getWidth() || getHeight > bufferedImage.getHeight())
                    {
                        getWidth = bufferedImage.getWidth();
                        getHeight = bufferedImage.getHeight();
                    }
                    
                    imageIcon = new ImageIcon(bufferedImage);
                    Graphics graphics = bufferedImage.createGraphics();
                    graphics.drawImage(image, 0, 0,getWidth ,getHeight , null, null);// ve anh theo kich thuoc da lay
                    Screen.this.jLabelShowImage.setIcon(imageIcon);
                }
            }
        };
        threadLoadImage.start();
    }//GEN-LAST:event_jButtonLoadImageActionPerformed

    private void jButtonZoomDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonZoomDownActionPerformed
      Thread threadZoomDown = new Thread()
        {
            @Override
            public void run()
            {
                if(bufferedImage == null) 
                    return;
                rate -= 0.1;
                //rate = Math.min(10, rate);
                
                ImageIcon imageIcon = new ImageIcon(bufferedImage);
                
                int width = (int)(imageIcon.getIconWidth()*rate);
                int height = (int)(imageIcon.getIconHeight()*rate);

                if(width > bufferedImage.getWidth() || height < bufferedImage.getHeight())
                {
                        width = bufferedImage.getWidth();
                        height = bufferedImage.getHeight();
                }
                
                
                
                AffineTransform affineTransform = new AffineTransform();
                affineTransform.setToScale(rate, rate);

                AffineTransformOp affineTransformOp = new AffineTransformOp(affineTransform , AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
                BufferedImage bufferedThumb = new BufferedImage(width , height, BufferedImage.TYPE_INT_ARGB);
                
                BufferedImage bufferedImage2 = affineTransformOp.filter(bufferedImage,bufferedThumb);
                imageIcon = new ImageIcon(bufferedImage2);
                
                //imageIcon = new ImageIcon(bufferedImage);
                
                Image image = imageIcon.getImage();
                Graphics graphics = bufferedImage2.createGraphics();
                graphics.drawImage(image, 0, 0,width ,height , null, null);// ve anh theo kich thuoc da lay
                
                Screen.this.jLabelShowImage.setIcon(imageIcon);
             }
        };
        threadZoomDown.start();  
    }//GEN-LAST:event_jButtonZoomDownActionPerformed

    public static void main(String args[]) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Screen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }

        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Screen().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCreateAlbum;
    private javax.swing.JButton jButtonLoadImage;
    private javax.swing.JButton jButtonMail;
    private javax.swing.JButton jButtonPrint;
    private javax.swing.JButton jButtonSearch;
    private javax.swing.JButton jButtonTurnLeft;
    private javax.swing.JButton jButtonTurnRight;
    private javax.swing.JButton jButtonZoomDown;
    private javax.swing.JButton jButtonZoomUp;
    private javax.swing.JLabel jLabelShowImage;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanelAlbum;
    private javax.swing.JPanel jPanelButton;
    private javax.swing.JPanel jPanelCreateAlbum;
    private javax.swing.JPanel jPanelSearch;
    private javax.swing.JPanel jPanelShowImage;
    private javax.swing.JPanel jPanelShowList;
    private javax.swing.JPanel jPanelShowSlide;
    private javax.swing.JTextField jTextFieldSearch;
    // End of variables declaration//GEN-END:variables
}
